from sqlalchemy import Column, Integer, String, DateTime
from config.database import Base
from datetime import datetime


class Datasource(Base):
    """
    数据源配置表
    """
    __tablename__ = 'datasource'

    datasource_id = Column(Integer, primary_key=True, autoincrement=True, comment='数据源主键')
    datasource_name = Column(String(100), nullable=False, comment='数据源名称')
    database_type = Column(String(100), nullable=False, comment='数据源类型')
    host = Column(String(100), nullable=True, comment='主机')
    port = Column(Integer, nullable=True, comment='端口号')
    user = Column(String(500), nullable=True, comment='用户名')
    password = Column(String(500), nullable=True, comment='密码')
    database = Column(String(500), nullable=True, comment='库名')
    charset = Column(String(500), nullable=True, default='utf8', comment='编码')
    client_encoding = Column(String(500), nullable=True, comment='客户端连接编码')
    connect_type = Column(String(500), nullable=True, comment='ORACLE 连接类型 Basic、TNS')
    service_name = Column(String(500), nullable=True, default='ORCL', comment='服务名')
    sid = Column(String(500), nullable=True, comment='数据库实例SID')
    dsn = Column(String(500), nullable=True, comment='oracle数据库dsn连接信息')
    encoding = Column(String(500), nullable=True, comment='客户端连接编码')
    nencoding = Column(String(500), nullable=True, comment='客户端连接编码')
    oracle_driver_path = Column(String(500), nullable=True, comment='Jar包路径')
    jar_file_name = Column(String(500), nullable=True, comment='Jar包名称')
    access_id = Column(String(500), nullable=True, comment='access_id')
    secret_access_key = Column(String(500), nullable=True, comment='secret_access_key')
    project = Column(String(500), nullable=True, comment='project')
    endpoint = Column(String(500), nullable=True, comment='endpoint')
    auth_mechanism = Column(String(500), nullable=True, comment='auth_mechanism')
    jdbc_url = Column(String(2000), nullable=True, comment='jdbc连接信息')
    program_name = Column(String(500), nullable=True, default='FastApiTools', comment='程序连接名称')
    create_by = Column(String(64), nullable=True, comment='创建者')
    create_time = Column(DateTime, nullable=True, default=datetime.now(), comment='创建时间')
    update_by = Column(String(64), nullable=True, comment='更新者')
    update_time = Column(DateTime, nullable=True, default=datetime.now(), comment='更新时间')
    remark = Column(String(500), nullable=True, comment='备注')
    status = Column(String(1), nullable=False, default='0', comment='状态（0正常 1停用）')
